﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Kaesoft.Hospedaje.Common
{
    public class EntityList<T> : ObservableCollection<T>
    {
        public event EventHandler CollectionClearing;

        public EntityList(IEnumerable<T> values)
            : base(values)
        {
        }

        public EntityList()
            : base()
        {
        }

        public void Clear()
        {
            if (this.Count > 0)
            {
                var oldList = new EntityList<T>(this);
                base.Clear();
                var collectionClearing = CollectionClearing;
                if (collectionClearing != null)
                    collectionClearing(oldList, new EventArgs());
            }
        }
    }
}